package com.example.springboot.work;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @program: 12-springboot-rabbitmq
 * @description: HelloSender
 * @author: Yuwl
 * @create: 2019-12-27 16:38
 **/
@Component
public class HelloSender {
	@Autowired
	private AmqpTemplate amqpTemplate;

	public void send() {
		String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());//24小时制
		String context = "hello " + date;
		System.out.println("Sender : " + context);
		//简单队列的情况下routekey即为Queue名
		this.amqpTemplate.convertAndSend("q_hello", context);
	}

	public void send2(int i) {
		String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());//24小时制
		String context = "hello " + i + " " + date;
		System.out.println("Sender : " + context);
		//简单队列的情况下routekey即为Queue名
		this.amqpTemplate.convertAndSend("q_hello", context);
	}
}
